<?php

class Disciplina_model extends CI_Model {

    private $tabla = 'disciplinas';

    function __construc() {
        parent::__construct();
    }

    /** Metodo Utilitario* */
    function _required($required, $data) {
        foreach ($required as $field)
            if (!isset($data[$field]))
                return false;

        return true;
    }

    function Guardar_disciplina($disciplina, $descripcion) {
        $data = array(
            'nomb_disciplina' => $disciplina,
            'descripcion' => $descripcion
        );
        $this->db->insert($this->tabla, $data);
        return $this->db->insert_id();
    }

//fin function

    function Obtener_disciplina() {
        $data = array();
        $q2 = $this->db->select('id_disciplina,nomb_disciplina');
        $q2 = $this->db->get($this->tabla);
        foreach ($q2->result_array() as $row2) {
            $data[] = $row2;
        }
        return($data);
    }

//fin function



    function Listar_disciplina($numeroRegistros, $inicio) {
        if ($numeroRegistros == "") {
            $numeroRegistros = 0;
        }
        $query = $this->db->query('SELECT id_disciplina,nomb_disciplina, descripcion
                                   FROM disciplinas  
                                   LIMIT ' . $numeroRegistros . ',' . $inicio);
        $dato=$query->result();
          
        return $query->result();
    }

//fin
    function Count_disciplina() {

        $query = $this->db->query('SELECT nomb_disciplina, descripcion
                                   FROM disciplinas');
        return $query->num_rows();
    }

//fin
    function Eliminar_disciplina($id_disciplina) {

        $query = $this->db->query('DELETE FROM disciplinas WHERE ID_DISCIPLINA=' . $id_disciplina);
        if ($error = $this->db->_error_number());
        return $error;
    }

      function Modificar_disciplina($id_disciplina, $disciplina,$descripcion) {
      
    //     $query2='UPDATE disciplinas SET NOMB_DISCIPLINA="'.$disciplina.'", DESCRIPCION="'.$descripcion.'" WHERE ID_DISCIPLINA=' . $id_disciplina;
          $query = $this->db->query('UPDATE disciplinas SET NOMB_DISCIPLINA="'.$disciplina.'", DESCRIPCION="'.$descripcion.'" WHERE ID_DISCIPLINA=' . $id_disciplina);
      //    echo "la query es "+$query2;
     
         if ($error = $this->db->_error_number());
         return $error;
    }
    
//fin
//
//
//
 
//fin class Disciplina_model
}
?>
